package jch.learn.java.advanced.chapter2_InputAndOutput.objectStream;

import java.io.*;

public class ObjectStreamExTest {

    public static void main(String[] args) throws IOException, ClassNotFoundException {

        EmployeeEx employeeEx = new EmployeeEx("zhangsan",1000,1993,10,11);
        String path = ObjectStreamExTest.class.getResource("/chapter2/employeeEx.txt").getPath();

        // 将对象写出文件
        try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(path,true))) {
            employeeEx.writeExternal(out);
            out.flush();
//            out.close();
        }

        // 从文件中读入
        try(ObjectInputStream in = new ObjectInputStream(new FileInputStream(path))){
            EmployeeEx ex = new EmployeeEx();
            ex.readExternal(in);
            in.close();
            System.out.println(ex);
        }

    }

}
